--- %%NOBANNER%% -->
/*-------------------<-- Start of Description -->--------------------\
| Generate random variate from a gamma distribution |
|--------------------<--- End of Description -->---------------------|
|--------------------------------------------------------------------|
|--------------<--- Start of Files or Arguments Needed -->-----------|
| Arguments Need: |
| seed - seed; Required, default is the current system time; |
| var - the variable to save the generated random variates; |
| alpha- alpha; |
| beta - beta; |
| Note: mean=alpha*beta, variance=alpha*beta^2; |
| temp - the temporary variable to update the seed; |
| default is _rangam0_; |
|---------------<--- End of Files or Arguments Needed -->------------|
|--------------------------------------------------------------------|
|----------------<--- Start of Example and Usage -->-----------------|
|Example |
| data one; |
| do i=1 to 20; |
| x=%_rangam(alpha=5, beta=2); |
| z=%_rangam(seed=1, alpha=10); |
| %_rangam(seed=1324, var=y, alpha=2, beta=5); |
| output; |
| end; |
| run; %print(one); |
|Usage: %_rangam(seed=%sysfunc(datetime(), 15.), var=, alpha=, beta=,|
| temp=_rangam0_); |
\-------------------<--- End of Example and Usage -->---------------*/
%macro _rangam(seed=%sysfunc(datetime(), 15.), var=, alpha=REQUIRED,
beta=, temp=_rangam0_);
/*--------------------------------------------\
| Author: Duo Zhou; |
| Created: 3-22-2002 6:30pm; |
| Purpose: Random Gamma Generator; |
\--------------------------------------------*/
%let _achk_=%sysfunc(rxmatch(%sysfunc(rxparse($a|$A|$w)),&alpha));
%if (%quote(&seed) eq) or &_achk_ %then %do;
%if (%quote(&seed) eq) %then %do;
%put ==> Error: This is not a valid seed!;
%if (%length(&var)) %then %do; &var=.; %end;
%else %do; .;%end;
%end;
%if &_achk_ %then %do;
%put ==> Error: &alpha is not a valid alpha!;
%if (%length(&var)) %then %do; &var=.; %end;
%else %do; .;%end;
%end;
%goto finish;
%end;
%else %do;
%if (%length(&var)) %then %do;
%if (not %sysfunc(rxmatch(%sysfunc(rxparse(_|.|$a|$A|$w)),&seed))) %then %do;
drop &temp;
retain &temp &seed;
%let seed=&temp;
%end;
call rangam(&seed, &alpha, &var);
%if (%length(&beta)) %then &var=&var;
%end;
%else rangam(&seed, &alpha);
%if (%length(&beta)) %then *β
%end;
%finish:
%mend _rangam;